package com.blog.controller;


import com.blog.common.Result.PageResult;
import com.blog.common.Result.Result;
import com.blog.dto.CommentAddDto;
import com.blog.service.ICommentService;
import com.blog.vo.CommentGetByArticleIdVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/comment")
@Api(tags = "评论相关接口")
@Slf4j
@RequiredArgsConstructor
public class CommentController {


    private final ICommentService commentService;


    /**
     * 添加文章评论
     * @param commentAddDto
     * @return
     */
    @PostMapping("/addCommentToArticle")
    @ApiOperation("添加文章评论")
    public Result<String> addCommentToArticle(@RequestBody CommentAddDto commentAddDto){
        log.info("添加文章评论:{}",commentAddDto);
        commentService.addCommentToArticle(commentAddDto);
        return Result.success("评论成功");
    }

    @DeleteMapping("/deleteComment/{commentId}")
    @ApiOperation("删除评论")
    public Result<String> deleteComment(@PathVariable Long commentId){
        log.info("删除评论:{}",commentId);
        commentService.deleteComment(commentId);
        return Result.success("删除成功");
    }

    /**
     * 获取文章评论列表
     * @param articleId
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/getCommentList/{articleId}")
    @ApiOperation("获取文章评论列表")
    public Result<PageResult> getCommentList(@PathVariable Long articleId,Integer pageNum,Integer pageSize){
        log.info("获取文章评论列表:{}",articleId);
        return Result.success(commentService.getCommentList(articleId,pageNum,pageSize));
    }
}
